public class ThreeNCalculator {

	private long mStartNum;
	private long mEndNum;
	private long mMaxCycleLength;

	public ThreeNCalculator(long startNum, long endNum) {
		setNumbers(startNum, endNum);
		this.mMaxCycleLength = calculateMaxCycleLength();
	}

	private void setNumbers(long startNum, long endNum) {
		if(startNum < endNum) {
			this.mStartNum = startNum;
			this.mEndNum = endNum;	
		} else {
			this.mEndNum = startNum;
			this.mStartNum = endNum;
		}
	}	

	public long calculateCycleLength(long number) {
		long count = 1;
		while(number != 1) {
			if(number % 2 == 0) {
				number = number >> 1;				
			} else {
				number = (3 * number) + 1;				
			}
			++count;
		}
		return count;
	}

	private long calculateMaxCycleLength() { 
		long result, maxCycleLength = -1;		

		for(long i = mStartNum; i <= mEndNum; ++i) {
			result = calculateCycleLength(i);			
			if(result > maxCycleLength)
				maxCycleLength = result;
		}
		return maxCycleLength; 
	}

	public long getEndNum() {
		return mEndNum;
	}

	public long getStartNum() {
		return mStartNum;
	}	

	public long getMaxCycleLength() {		
		return mMaxCycleLength;
	}
}